package com.sxxm.qxgl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sxxm.qxgl.entity.SysRole;
import com.sxxm.qxgl.entity.UserRole;
import com.sxxm.qxgl.mapper.UserRoleMapper;
import com.sxxm.qxgl.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxxm.qxgl.vo.Result;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 用户角色关系表 服务实现类
 * </p>
 *
 * @author qjw
 * @since 2021-09-14
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    UserRoleMapper userRoleMapper;
    public UserRoleServiceImpl(UserRoleMapper userRoleMapper){
        this.userRoleMapper=userRoleMapper;
    }
    @Override
    public Result Batch_add(UserRole userRoles) {
        userRoleMapper.insert(userRoles);
//        userRoleMapper.insert(userRoles.get(0));
        return Result.ok().message("成功").data("成功");
    }

    @Override
    public Result Delete(UserRole userRoles) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("roleId",userRoles.getRoleId());

        int sum = userRoleMapper.deleteByMap(map);
        if (sum <= 0) {
            return Result.error().message("失败");
        }
        return Result.ok().message("成功").data("成功");
    }
}
